package ScreensManager 
{
	import flash.display.MovieClip;
	import ScreensManager.ProjectScreen.GameScreen
	import ScreensManager.ProjectScreen.IntroductionScreen
	import ScreensManager.ProjectScreen.MenuScreen
	import ScreensManager.ProjectScreen.PauseScreen;
	import ScreensManager.ProjectScreen.ScoreScreen;
	import ScreensManager.ProjectScreen.Screens
	/**
	 * ...
	 * @author Thiago
	 */
	public class ScreenManager extends MovieClip
	{
		private static var currentScreen:Screen;
		public static var main:Main;
		private static var overwrite:Screen;
		
		public function ScreenManager() 
		{
			
		}
		
		public static function getCurrentScreen():Screen
		{
			return currentScreen;
		}
		
		public static function setCurrentScreen(screen:int):void 
		{
			/* adicione mais um case para uma tela nova ser desenhada
			 * Exemplo:
				 * case Screens.NOVA_TELA
				 * clearScreen();
				 * var novaTela:TelaNova = new TelaNova();
				 * novaTela.drawScreen();
				 * currentScreen = novaTela
				 * brea;
			 */
			
			switch(screen)
			{
				case Screens.INTRODUCTION_SCREEN:
					clearScreen();
					var introductionScreen:IntroductionScreen = new IntroductionScreen();
					introductionScreen.drawScreen();
					currentScreen = introductionScreen;
				break;
				
				case Screens.MENU_SCREEN:
					clearScreen();
					var menuScreen:MenuScreen = new MenuScreen();
					menuScreen.drawScreen();
					currentScreen = menuScreen;
				break;
				
			case Screens.GAME_SCREEN:
					clearScreen();
					var gameScreen:GameScreen = new GameScreen(main);
					gameScreen.drawScreen();
					currentScreen = gameScreen;
				break;
				
			case Screens.SCORE_SCREEN:
					clearScreen();
					var scoreScreen:ScoreScreen = new ScoreScreen();
					scoreScreen.drawScreen();
					currentScreen = scoreScreen;
				break;
				
			case Screens.PAUSE_SCREEN:
					clearScreen();
					var pauseScreen:PauseScreen = new PauseScreen();
					pauseScreen.drawScreen();
					currentScreen = pauseScreen;
				break;
			}
		}
		
		private static function clearScreen():void
		{
			if (currentScreen)
			{
				trace(currentScreen)
				currentScreen.removeListeners();
				Main.getInstance().removeChild(currentScreen);
				currentScreen = null;
			}
		}
		
		public static function overwriteScreen(screen:int):void
		{
			switch(screen)
			{
				case Screens.INTRODUCTION_SCREEN:
					var introductionScreen:IntroductionScreen = new IntroductionScreen();
					introductionScreen.drawScreen();
					overwrite = introductionScreen;
				break;
				
				case Screens.MENU_SCREEN:
					var menuScreen:MenuScreen = new MenuScreen();
					menuScreen.drawScreen();
					overwrite = menuScreen;
				break;
				
			case Screens.GAME_SCREEN:
					var gameScreen:GameScreen = new GameScreen(main);
					gameScreen.drawScreen();
					overwrite = gameScreen;
				break;
				
			case Screens.SCORE_SCREEN:
					var scoreScreen:ScoreScreen = new ScoreScreen();
					scoreScreen.drawScreen();
					overwrite = scoreScreen;
				break;
				
			case Screens.PAUSE_SCREEN:
					var pauseScreen:PauseScreen = new PauseScreen();
					pauseScreen.drawScreen();
					overwrite = pauseScreen;
				break;
			}
		}
		
		public static function deleteOverwrittenScreen()
		{
			overwrite.removeListeners();
			Main.getInstance().removeChild(overwrite);
			overwrite = null;
		}
	}

}